package MovieGuessingGame.player;

import org.apache.commons.lang3.StringUtils;

public class TitleCompare {

	String mMovieTitle;
	
	String mMaskedTitle;
	
	int currentScoreIncrease = 0;
	
	public int getCurrentScoreIncrease(String value) {
		String finalCountString = new String(mMaskedTitle);

		int finalCharCount = StringUtils.countMatches(finalCountString, value);

		return finalCharCount;
	}

	public String getmMovieTitle() {
		return mMovieTitle;
	}

	public String getmMaskedTitle() {
		return mMaskedTitle;
	}

	public TitleCompare(String mMovieTitle) {
		super();
		this.mMovieTitle = mMovieTitle;
	}
	
	public void convertToStars()
	{
		String regex = "[A-Za-z]";
		mMaskedTitle = mMovieTitle.replaceAll(regex, "*");
	}
	
	public int getInitialStarCount(){
		this.convertToStars();
		int initCharCount = StringUtils.countMatches(mMaskedTitle, "*");
		return initCharCount;
	}
	public boolean didWin(String unMaskedTitle){
		int finalCharCount = StringUtils.countMatches(unMaskedTitle, "*");
		if (finalCharCount == 0) return true;
		else return false;
	}
	public void unMaskStars(String[] letters)
	{
		String letter = null;
		mMaskedTitle = mMovieTitle;
		
		for (int i=0;i<letters.length;i++)
		{
			letter = letters[i];
			String upper = letter.toUpperCase();
			String lower = letter.toLowerCase();
			String regex = "["+ upper +"]";
			mMaskedTitle = mMaskedTitle.replaceAll(regex, "%"+i);
			regex = "["+ lower +"]";
			mMaskedTitle = mMaskedTitle.replaceAll(regex, "%"+i);
			//System.out.println(mMaskedTitle+"\n");
		}
		
		String regex = "[A-Za-z]";
		mMaskedTitle = mMaskedTitle.replaceAll(regex, "*");
		for (int i=letters.length-1;i>=0;i--)
		{		
			mMaskedTitle = mMaskedTitle.replaceAll("%"+i, letters[i]);
		}
		

	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String testTitle = "The Good, The Bad, and the Ugly";
		TitleCompare titleCompare = new TitleCompare(testTitle);
		titleCompare.convertToStars();
		//System.out.println(titleCompare.getmMaskedTitle());
		String[] testData = {"T","h"};
		titleCompare.unMaskStars(testData);

		//System.out.println(titleCompare.getmMaskedTitle());

	}

}
